home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / pexit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  2.5 KB  |  134 lines

  1. /*
  2.  * Exit Pcomm.  A user requested abort.  There are a lot of things to do
  3.  * before we exit!
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <curses.h>
  8. #include "config.h"
  9. #include "dial_dir.h"
  10. #include "misc.h"
  11. #include "param.h"
  12. #include "status.h"
  13.  
  14. #ifdef SHAREDMEM
  15. #include <sys/types.h>
  16. #include <sys/ipc.h>
  17. #include <sys/shm.h>
  18. #endif /* SHAREDMEM */
  19.  
  20. void
  21. pexit()
  22. {
  23.     extern int fd;
  24.     WINDOW *ex_win, *newwin();
  25.     void cleanup(), st_line();
  26.  
  27.     ex_win = newwin(5, 33, 3, 7);
  28.  
  29.     box(ex_win, VERT, HORZ);
  30.     mvwattrstr(ex_win, 0, 3, A_BOLD, " Exit ");
  31.     if (yes_prompt(ex_win, 2, 4, A_BLINK, "Exit to Unix")) {
  32.         st_line("   exiting");
  33.         cleanup(0);
  34.     }
  35.     if (fd == -1) {
  36.         werase(ex_win);
  37.         wrefresh(ex_win);
  38.     }
  39.     delwin(ex_win);
  40.     return;
  41. }
  42.  
  43. /*
  44.  * Do the clean up detail before we exit.  Only the status structure
  45.  * is guaranteed to exit.
  46.  */
  47.  
  48. void
  49. cleanup(val)
  50. int val;
  51. {
  52.     extern int msg_status;
  53.     void release_port(), input_off(), exit();
  54.     char *mytty, *ttyname();
  55. #ifdef SHAREDMEM
  56.     extern int shm_id;
  57.     void perror();
  58. #endif /* SHAREDMEM */
  59.                     /* kill the input routine */
  60.     input_off();
  61.                     /* release the port */
  62.     release_port(QUIET);
  63.                     /* zap the virtual screen */
  64. #ifdef SHAREDMEM
  65.     if (shmdt((char *) status) < 0)
  66.         perror("shmdt");
  67.     if (shmctl(shm_id, IPC_RMID, (struct shmid_ds *) NULL) < 0)
  68.         perror("shmctl");
  69. #else /* SHAREDMEM */
  70.     unlink(status->vs_path);
  71. #endif /* SHAREDMEM */
  72.  
  73.     /*
  74.      * If we die an un-natural death (such as a SIGHUP on the loss of
  75.      * the controlling terminal) we won't have a terminal to mess with.
  76.      */
  77.     if (isatty(0)) {
  78.         touchwin(stdscr);
  79.         clear();
  80.         refresh();
  81.         endwin();
  82.                     /* return the TTY chmod */
  83.         if (mytty = ttyname(0))
  84.             chmod(mytty, msg_status);
  85.     }
  86.     exit(val);
  87. }
  88.  
  89. /*
  90.  * Open a window to display an error message.  Handles both fatal and
  91.  * non-fatal errors
  92.  */
  93.  
  94. void
  95. error_win(code, line_one, line_two)
  96. int code;
  97. char *line_one, *line_two;
  98. {
  99.     WINDOW *e_win, *newwin();
  100.     void cleanup(), st_line();
  101.  
  102.                     /* make sure we're in curses mode */
  103.     fixterm();
  104.     e_win = newwin(7, 70, 9, 5);
  105.                     /* display the nasty note */
  106.     mvwaddstr(e_win, 2, 4, line_one);
  107.     mvwaddstr(e_win, 3, 4, line_two);
  108.     box(e_win, VERT, HORZ);
  109.  
  110.     if (code) {
  111.         mvwattrstr(e_win, 0, 4, A_BOLD, " Error ");
  112.         mvwattrstr(e_win, 5, 24, A_BLINK, "Press any key to exit");
  113.         wmove(e_win, 5, 46);
  114.     }
  115.     else {
  116.         mvwattrstr(e_win, 0, 4, A_BOLD, " Warning ");
  117.         mvwattrstr(e_win, 5, 22, A_BLINK, "Press any key to continue");
  118.         wmove(e_win, 5, 48);
  119.     }
  120.     beep();
  121.     wrefresh(e_win);
  122.  
  123.     wgetch(e_win);
  124.     werase(e_win);
  125.     wrefresh(e_win);
  126.     delwin(e_win);
  127.  
  128.     if (code) {
  129.         st_line("   exiting");
  130.         cleanup(code);
  131.     }
  132.     return;
  133. }
  134.